home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13934 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.3 KB

  1. Path: news.sprintlink.net!datalytics!usenet
  2. From: Rob Stewart <stew@datalytics.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Coding Standards
  5. Date: Wed, 27 Mar 1996 16:53:52 -0500
  6. Organization: Datalytics, Inc
  7. Message-ID: <3159B8F0.22C6@datalytics.com>
  8. References: <4hj8ek$elu@sam.inforamp.net> <4hktar$5o2@galaxy.ucr.edu> <4io1a4$n9v@sam.inforamp.net> <4j8sdf$575@slbh00.bln.sel.alcatel.de>
  9. NNTP-Posting-Host: 204.62.224.71
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (WinNT; I)
  14.  
  15. Marc Furguson wrote:
  16. > Randy Charles Morin (rmorin@inforamp.net) wrote:
  17. > : In article <CBARBER.96Mar18104644@figaro.bbn.com>,
  18. > :    cbarber@bbn.com (Christopher Barber) wrote:
  19. >         --- snip ---
  20. > : >    Randy>   -a class which can be instantiated with a "new" must have a
  21. > : >    Randy> copy constructor, a destructor and an assignment operator
  22. > : >    Randy> definition.  Most compilers (if not all) supply default copy
  23. > : >    Randy> construtors.  Unless you think your class may have copy behavior
  24. > : >    Randy> problems, then writing copy constructors is redundant.  When you
  25. > : >    Randy> have 100+ classes to write and where the average copy
  26. > : >    Randy> constructor has 50 lines, you would need 100 hours to write the
  27. > : >    Randy> additional robustness (or cumbersomeness).
  28. > : >Aren't you getting a bit extreme here?  I have written hundreds of
  29. > : >copy constructors and only a handful came even close to 50 lines long.
  30. > : >Yes, the compiler will generate a copy constructor for you, but it
  31. > : >has the wrong behavior in many cases.
  32. > : Where am I being a little extreme?  We do have 100+ classes, I have already
  33. > : identified about 100.  I calculated the average amount of lines per copy
  34. > : constructor in another project and it came out just below 50.  The average
  35. > : programmer on that project wrote less than 50 lines an hour.  That's 100
  36. > : hours.  It's math.
  37. >         --- snip ---
  38. > : Agrivar
  39.  
  40. I can locate 100+ classes in my work and that of my coworkers.  
  41. I don't think any of them have 50 line copy ctors.  My questions 
  42. are whether there are other functions (members or not) that 
  43. would offload some of the behavior or whether the classes have 
  44. too many dms.  Most copy ctors do about what a normal ctor 
  45. does--they must initialize or assign to the same dms--with some 
  46. additional logic in place to handle reference counting or 
  47. resource duplication.
  48.  
  49. How is your copy ctors come to be so long?
  50.  
  51. > Seems reasonable to me. It's not just a case of typing in copy constructors,
  52. > destructors etc. If the compiler does it just fine then let it. If you need
  53. > something else then code it, test it and document it. Now, 
  54.  
  55. That's the right attitude.  Write the rule to encompass the 
  56. circumstances under which you must provide your own copy ctor.  
  57. Then, those understanding the rule will write a copy ctor when 
  58. needed and can allow the compiler to do it when that is 
  59. appropriate.
  60.  
  61. >maybe I'm just
  62. > slow but I take a *lot* longer to test and document my software than I
  63. > take to write it, so I'd rather not write it in the first place if I
  64. > don't have to! On the other hand if your code is completely self-
  65. > documenting and is *always* faultless then just keep bashing away!
  66.  
  67. -- 
  68. Robert Stewart        | My opinions are usually my own.
  69. Datalytics, Inc.    | stew@datalytics.com
  70.